<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * hasilproses.php
 * @author ranuandra
 *
 * 8 Mei 2012 10:36:15
 *
 * 
 */

class Controller_Admin_Hasilproses extends Kohana_Admin
{
	
	public function action_hasil()
	{
		$this->auto_render = false;
		$pelamarproses_id = Request::current()->param('id');
		
		$view = View::factory('admin/hasilproses/form');
		$view->pelamarproses_id = $pelamarproses_id;
		echo $view;
		exit;
	}
	
	public function action_save()
	{
		if($_POST)
		{
			$db = Database::instance();
			$db->begin();
			try 
			{
				$year = date("Y");
				$month = date("m");
				$mx = DB::select(array('MAX("id")', 'maks'))->from('hasilproseses')->execute();

				$no = $mx[0]['maks'] + 1;
				
				$hasil = ORM::factory('hasilproses');
				$hasil->user_id = Auth_ORM::instance()->get_user()->id;
				$hasil->kode = "HSL-".$year.$month."-".$no;
				$hasil->tgl = date("Y-m-d");
				$hasil->create_data($_POST);
				

				
				
				$db->commit();
				
				$lowongan = ORM::factory('pelamarproses', Request::current()->post('pelamarproses_id'));
				return Request::current()->redirect(URL::base().'admin/proseslowongan/pelamar/'.$lowongan->id);
			}
			catch(ORM_Validation_Exception $e)
			{
				$db->rollback();
				$errors = $e->errors('models');
				print_r($errors);				
			}
		}
		
		
	}
}